package com.nancy.java_design.responsibility.demo1;

/**
 * 责任链模式
 * 以 请假为例
 */
public abstract class Handler {
    protected final Integer NUM_ONE = 1;
    protected final Integer NUM_THREE = 3;
    protected final Integer NUM_SEVEN = 7;

    //各个级别审批人能够审批的天数
    private Integer dayStart;
    private Integer dayEnd;

    //下一个审批人
    protected Handler handler;

    public void setHandler(Handler handler) {
        this.handler = handler;
    }

    //处理请求
    public abstract void handleRequest(RequestLeave request);

    //提交请求
    public final void passRequest(RequestLeave requestLeave) {
        if (requestLeave == null) throw new RuntimeException("系统错误！请联系管理员");
        //审批人审批
        handleRequest(requestLeave);
        System.out.println("" + requestLeave.getName() + "申请了【" + requestLeave.getDays() + "】天的假期，理由：" + requestLeave.getReason());
    }

}
